package com.example.djs;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {
    private TextView tvCountDown;
    private final int countDownMaxTime = 5000;
    private final int countDownInterval = 1000;
    private final CountDownTimer countDownTimer = new CountDownTimer(countDownMaxTime, countDownInterval) {
        @Override
        public void onTick(long millisUntilFinished) {
            tvCountDown.setText(String.valueOf((int) (millisUntilFinished / countDownInterval)));
        }
        @Override
        public void onFinish() {
            Intent intent = new Intent(MainActivity.this, MainActivity2.class);
            MainActivity.this.startActivity(intent);
            MainActivity.this.finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvCountDown = findViewById(R.id.tvCountDown);
    }

    @Override
    protected void onStart() {
        super.onStart();
        countDownTimer.start();
    }
}